<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/js/my.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">

    <form class="layui-form" id="EditForm">
        <div class="layui-form-item">
            <label for="returnId" class="layui-form-label">
                <span class="x-red">*</span>退货编号
            </label>
            <div class="layui-input-inline">
                <input th:value="${reinfo.returnId}" id="returnId" name="returnId" required="" autocomplete="off" class="layui-input" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="outId" class="layui-form-label">
                <span class="x-red">*</span>出库编号
            </label>
            <div class="layui-input-inline">
                <input th:value="${reinfo.outId}" id="outId" name="outId" required="" autocomplete="off" class="layui-input" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="productName" class="layui-form-label">
                <span class="x-red">*</span>产品名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="productName" th:value="${reinfo.productName}" name="productName" required="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="returnDate" class="layui-form-label">
                <span class="x-red">*</span>退货日期
            </label>
            <div class="layui-input-inline">
                <input  id="returnDate" name="returnDate"th:value="${reinfo.returnDate}" required=""  class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="returnQuantity" class="layui-form-label">
                <span class="x-red">*</span>退货数量
            </label>
            <div class="layui-input-inline">
                <input type="text" id="returnQuantity" th:value="${reinfo.returnQuantity}"name="returnQuantity" required="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="clientName" class="layui-form-label">
                <span class="x-red">*</span>客户
            </label>
            <div class="layui-input-inline">
                <select id="clientName" style="width: 150px; height: 25px" name="clientName">
                </select>
                <input style="display:none;" type="text" id="thisClientName" th:value="${reinfo.clientName}" name="thisClientName" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="returnReason" class="layui-form-label">
                <span class="x-red">*</span>退货原因
            </label>
            <div class="layui-form-item layui-form-text">
                <input type="text" id="returnReason"th:value="${reinfo.returnReason}" name="returnReason" required="" autocomplete="off"
                       class="layui-textarea">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="returnAmount" class="layui-form-label">退货总金额</label>
            <div class="layui-input-inline">
                <input type="text" id="returnAmount" th:value="${reinfo.returnAmount}"name="returnAmount" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>

            <div class="layui-form-item">
                <label for="warehouseName" class="layui-form-label">
                    <span class="x-red">*</span>仓库名称
                </label>
                <div class="layui-input-inline">
                    <select id="warehouseName" style="width: 150px;height: 25px" name="warehouseName">
                    </select>
                    <input style="display:none;" type="text" id="thisWarehouseName" th:value="${reinfo.warehouseName}" name="thisStorageName" required=""
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="administrator" class="layui-form-label">
                    <span class="x-red">*</span>仓库管理员
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="administrator"th:value="${reinfo.administrator}" name="administrator" required="" autocomplete="off" class="layui-input" oninput="getAdministrator()">
                </div>
            </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="modify" lay-submit="">
                修改
            </button>
        </div>
    </form>
</div>
<script type="text/javascript">

    function getAdministrator() {
        var name = $("#warehouseName").val();
        $.ajax({
            url:"/productReturn/getAdministrator",
            type:"get",
            data:{"name":name},
            dataType:"json",
            success:function (date) {
                document.getElementById("administrator").value = date;
            }
        })
    }


</script>
<script>
    //定义文档加载函数
    $(function(){
        //加载客户
        loadClient();
        //加载仓库名称
        loadWarehouseName();
    })


    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#returnDate' //指定元素
        });
    });


    //加载客户
    function loadClient() {
        var thisClientName=$("#thisClientName").val();
        $.ajax({
            url:"/productReturn/clientName",
            async: false,
            type:"get",
            dataType:"json",
            success:function (data) {
                //创建一个拼接字符串的变量
                var html = "";
                html += "<option value='"+thisClientName+"'>"+thisClientName+"</option>";
                //遍历服务端传来的数据集合，就是json数据
                for (var i = 0 ; i < data.length ; i++){
                    html += "<option value='"+data[i].legal_person+"'>"+data[i].legal_person+"</option>";
                }
                //把html加载到下拉框
                $("#clientName").html(html);
            }
        })
    }
    //加载仓库名字
    function loadWarehouseName() {
        var thisWarehouseName=$("#thisWarehouseName").val();
        $.ajax({
            url:"/productReturn/warehouseName",
            async: false,
            type:"get",
            dataType:"json",
            success:function (data) {
                //创建一个拼接字符串的变量
                var html = "";
                html += "<option value='"+thisWarehouseName+"'>"+thisWarehouseName+"</option>";
                //遍历服务端传来的数据集合，就是json数据
                for (var i = 0 ; i < data.length ; i++){
                    html += "<option value='"+data[i].name+"'>"+data[i].name+"</option>";
                }
                //把html加载到下拉框
                $("#warehouseName").html(html);
            }
        })
    }
</script>
<script>


    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            storageNum: function(value) {
                //创建一个正则表达式对象
                var re = /^[0-9]*$/;
                //验证用户输入的入库数量是否是数字
                if (!re.test(value)) {
                    layer.alert( "退货数量必须为数字！");
                }
            }
        });

        //监听提交
        form.on('submit(modify)', function(data){
            $.ajax({
                url:server_address+"/productReturn/updateAjax",
                type:"post",
                data:data.field,
                dataType:"json",//返回的数据类型
                success:function(data){
                    //定义{info:"修改成功"}
                    $("#info").text(data);
                    //如果修改成功就跳转到登录页面
                    if(data.info == "修改成功"){
                        layer.alert("修改成功",function(index) {
                            //关闭弹窗操作
                            //获取Frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭弹窗
                            parent.layer.close(index);
                            //刷新
                            $(obj).parent().parent().remove();
                        });
                    }else{
                        layer.alert("修改失败");
                    }
                }
            })
            return false;
        });
    });

</script>
<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>l>